package com.rqf.mr.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.rqf.mr.service.IBedService;
import com.rqf.mr.service.IOrderService;
import com.rqf.mr.service.IPatientService;
import com.rqf.mr.service.impl.OrderService;
import com.rqf.mr.service.impl.PatientService;
import com.server.web.JSONSerielizer;
import com.server.web.OutputUtil;

/**
 * 医嘱
 * @author HelloWorld_luo
 * @date 2016年4月19日
 */
@Controller
@RequestMapping("order")
public class OrderController {

	@Autowired
	private IBedService bedService;
	@Autowired
	private IPatientService patientService;
	@Autowired
	private IOrderService orderService;

	@RequestMapping("list/{type}/{inpatiId}")
	public void getList(HttpServletRequest request,
			HttpServletResponse response, @PathVariable String type, @PathVariable String inpatiId) {
		if ( type.equals("longtime") ) {
			type = "长期";
		}else if ( type.equals("temporary") ) {
			type = "临时";
		}
		List<Map<String, Object>> list = orderService.getOrderListByInpatiIdCodename(inpatiId, type);
		String json = JSONSerielizer.toJson(list, null, null);
		OutputUtil.returnJsonp(request, response, json);
	}
	
	@RequestMapping("list/notcheck/{inpatiId}")
	public void getNotCheckList(HttpServletRequest request,
			HttpServletResponse response, @PathVariable String inpatiId) {
		List<Map<String, Object>> list = orderService.getOrderByInpatiId(inpatiId);
		String json = JSONSerielizer.toJson(list, null, null);
		OutputUtil.returnJsonp(request, response, json);
	}
	
	@RequestMapping("list/checked/{inpatiId}")
	public void getCheckedList(HttpServletRequest request,
			HttpServletResponse response, @PathVariable String inpatiId) {
		List<Map<String, Object>> list = orderService.searchOrderHaveChecked(inpatiId);
		String json = JSONSerielizer.toJson(list, null, null);
		OutputUtil.returnJsonp(request, response, json);
	}
	
	@RequestMapping("check/{orderId}/{nurseLoginId}")
	public void checkOrder(HttpServletRequest request,
			HttpServletResponse response,@PathVariable String orderId,@PathVariable String nurseLoginId){
		Boolean result = false;
		result =  orderService.startOrder(orderId, nurseLoginId);
		OutputUtil.returnJsonp(request, response, result.toString());
	}
	
}
